package com.example.tijianserver.controller;

import com.example.tijianserver.dto.OrdersPageRequestDto;
import com.example.tijianserver.pojo.Orders;
import com.example.tijianserver.response.ApiRestResponse;
import com.example.tijianserver.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController  // @Controller  +  @ResponseBody
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    OrdersService ordersService;

    @RequestMapping("/createorder")  //所以url请求：  http://localhost:8080/users/register 记住还要参数json字符串
    public ApiRestResponse createorder(@RequestBody Orders orders){

        return ordersService.InsertOrders(orders);

    }

    //用户已支付订单列表
    @RequestMapping("/getOrderList")  //所以url请求：  http://localhost:8080/users/register 记住还要参数json字符串
    public ApiRestResponse getOrderList(@RequestBody Orders orders){

        return ApiRestResponse.success(ordersService.getOrder(orders));

    }

    //用户已完成订单列表
    @RequestMapping("/getReportList")  //所以url请求：  http://localhost:8080/users/register 记住还要参数json字符串
    public ApiRestResponse getReportList(@RequestBody Orders orders){

        return ApiRestResponse.success(ordersService.getReport(orders));

    }

    //医生体检订单列表
    @RequestMapping("/listOrders")
    public ApiRestResponse listOrders(@RequestBody OrdersPageRequestDto request) {
        return ApiRestResponse.success(ordersService.listOrders(request));
    }

    //取消订单
    @RequestMapping("/cancelOrder")
    public ApiRestResponse<?> cancelOrder(@RequestBody Map<String, Object> params){
        Integer orderId = (Integer) params.get("orderId");
        System.out.println(orderId);
        return ApiRestResponse.success(ordersService.cancelOrder(orderId));
    }

    //通过orderId查找orders
    @RequestMapping("/getOrdersById")
    public Orders getOrdersById(@RequestBody Orders orders) {
        System.out.println("这是/getOrdersById传的参数"+orders);
        Orders order=ordersService.getOrdersById(orders.getOrderId());
        System.out.println("这是getOrdersById查询到的"+order);
        return ordersService.getOrdersById(orders.getOrderId());
    }

    //    总监报告归档
    @RequestMapping("/updateOrdersState")
    public int updateOrdersState(@RequestBody Orders orders) {
        System.out.println(orders.getOrderId()+"state:"+orders.getState());
        return ordersService.updateOrdersState(orders);
    }
}
